/********************************************************************
	file name:	hy_script_module.h
	created:	2012/03/16 21:08
	author:		supercaco@sina.com
	purpose:	script interface
*********************************************************************/
#ifndef _HY_SCRIPT_MODULE_H_
#define _HY_SCRIPT_MODULE_H_

#include "hy_server_base.h"
#include "hy_thread.h"

const char * c_script_entry = "entry";
const char * c_lua_start_file = "start.lua";


class hy_script_module 
	: virtual public hy_module_base
	, virtual public hy_script_base
{
	enum hy_script_type
	{
		hst_lua, //lua script
		hst_end
	};
public:
	hy_script_module(const char* start_file,const char* entry, hy_script_type hst = hst_lua)
		:_start_file(start_file),_entry(entry)
	{
		switch(hst)
		{
		case  hst_end:
		default:
			{
				_script = new hy_script_lua(start_file);
				break;
			}
		}
	}

	virtual hy_err_t init() 
	{
		return _script->init();
	}

	virtual hy_err_t unit() 
	{
		return _script->unit();
	}

	virtual void	 run()
	{
		_thread =  new hy_thread(bind_thread(&hy_script_base::_run,_script,NULL));
	}

	virtual hy_err_t checkin(const char* funcname,const char* scriptfuncname)
	{
		return _script->checkin(funcname,scriptfuncname);
	}

protected:
	std::string		_start_file;
	std::string		_entry;
	hy_script_base* _script;
	hy_thread*		_thread;		
};

#endif // _HY_SCRIPT_MODULE_H_
